<?php
header("Content-type:text/html; charset=utf-8;");
require '../../../ppf/fun.php';
require '../../../ppf/pdo_mysql.php';
require '../../../ppf/Filter.php';
date_default_timezone_set("PRC");
$pd=new pdo_mysql();
$filter=new Filter();
session_start();
if(empty($_SESSION['uid'])){
	echo '请登录后再进行操作';exit;
}


$submitMethod=$_SERVER["REQUEST_METHOD"];
if($submitMethod=='POST'){
	$id          =empty($_POST['id'])?0:Filter::filter_number($_POST['id']);
	$refuse_reason = Filter::safe_string($_POST['content']);
    $status = $_POST['status'];
	$in_data=array(
		'status'=>'9',
        'refuse_reason'=>$refuse_reason
	);
	$result=0;
	$tps='';
	$result=$pd->update(array('data'=>$in_data,'table'=>'sys_takes_list','where'=>"id=".$id));
	$in_data_code=array(
        'takes_id'=>$id,
        'takes_user_id'=>$_SESSION['uid'],
		'takes_stauts'=>$status,
		'takes_code'=>$refuse_reason
	);
    $sql = $pd->query("select * from sys_takes_codes WHERE  takes_id=".$id." and takes_user_id='".$_SESSION['uid']."'")->fetchAll(PDO::FETCH_ASSOC);
    if(count($sql) == 0){
        $pd->insert(array('data'=>$in_data_code,'table'=>'sys_takes_codes'));
    }else{
        unset($in_data_code['takes_id']);
        unset($in_data_code['takes_user_id']);
        $pd->update(array('data'=>$in_data_code,'table'=>'sys_takes_codes','where'=>"takes_id=".$id." and takes_user_id='".$_SESSION['uid']."'"));
    }

	//print_r($result);exit;
	if(empty($result)){
		$tps='操作失败,请重试';
	}else{
		//return '1';
		$tps='操作成功';
	}

	echo $tps;exit;
}else{
	echo "不允许的表单提交方式，请按正常流程提交表单。";exit;
}
?>